package org.dreamfly.core.util;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Created by IntelliJ IDEA.
 * User: Gin
 * Date: 2010-12-2
 * Time: 16:38:43
 * To change this template use File | Settings | File Templates.
 */
public class ChangeChinese {
    public static  URL changeURL(URL srcUrl){
        String srouce = null;
        try {
            srouce = URLEncoder.encode(srcUrl.toString(),"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        srouce = srouce.replace("%2F","/");
        srouce = srouce.replace("%3A",":");
        srouce = srouce.replace("+"," ");
       URL tarUrl = null;
        try {
           tarUrl = new URL(srouce);
        } catch (MalformedURLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return tarUrl;
    }
    
    public static String changeFilePath(String src){
        String srouce = null;
        try {
            srouce = URLEncoder.encode(src.toString(),"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        srouce = srouce.replace("%2F","/");
        srouce = srouce.replace("%3A",":");
        srouce = srouce.replace("+"," ");
        return srouce;
    }
}
